package com.huawei;

import java.sql.SQLOutput;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * Created by Z-hong on 2024/7/11.
 */

public class HJ88 {
    static final Map<String,Integer> map=new HashMap<String,Integer>() {{
        put("3", 1);
        put("4", 2);
        put("5", 3);
        put("6", 4);
        put("7", 5);
        put("8", 6);
        put("9", 7);
        put("10", 8);
        put("J", 9);
        put("Q", 10);
        put("K", 11);
        put("A", 12);
        put("2", 13);
        put("joker",14);
        put("JOKER",15);
    }};

    static final String joker="joker JOKER";
    //个
    static final int A=1;
    //对
    static final int P=2;
    //顺
    static final int S=3;
    //三
    static final int T=4;
    //炸弹
    static final int B=5;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        if(input.contains(joker)){
            System.out.println(joker);
            return;
        }
        String[] split = input.split("-");
        int str_1=judgment(split[0]);
        int str_2=judgment(split[1]);
        String[] char_1=split[0].split(" ");
        String[] char_2=split[1].split(" ");
        String result = "ERROR";

        if(str_2==B&&str_1==B){
             result = map.get(char_1[0]) > map.get(char_2[0]) ? split[0] : split[1];
        }else if(str_2==B||str_1==B){
            result = str_2==B?split[1]:split[0];
        }else if(str_2==A&&str_1==A){
            result = map.get(char_1[0]) > map.get(char_2[0]) ? split[0] : split[1];
        }else if(str_2==P&&str_1==P){
            result = map.get(char_1[0]) > map.get(char_2[0]) ? split[0] : split[1];
        }else if(str_2==S&&str_1==S){
            result = map.get(char_1[0]) > map.get(char_2[0]) ? split[0] : split[1];
        }else if(str_2==T&&str_1==T){
            result = map.get(char_1[0]) > map.get(char_2[0]) ? split[0] : split[1];
        }
        System.out.println(result);
    }
    public static int judgment(String str){
        String[] charArray = str.split(" ");
        if (charArray.length==1){
            return A;
        }else if(charArray.length==2){
            return P;
        }else if(charArray.length==3){
            return T;
        }else if(charArray[0] .equals( charArray[1])){
            return B;
        }else{
            return S;
        }
    }
}
